package logenum

import (
	"yunj/pkg/yunj/core/enum"
)

// 定义常量
const (
	// 页面加载
	TYPE_VIEW_LOAD int = 11

	// 页面卸载
	TYPE_VIEW_UNLOAD int = 22
)

// 实现EnumInerface接口
type Type struct {
	enum.Enum[int]
}

func (e *Type) AllConstAttrs() map[int]map[string]any {
	return map[int]map[string]any{
		TYPE_VIEW_LOAD: {
			"desc":  "页面加载",
			"sort":  1,
			"color": "#16baaa",
		},
		TYPE_VIEW_UNLOAD: {
			"desc":  "页面卸载",
			"sort":  2,
			"color": "#ffb800",
		},
	}
}

// instanceCache 存储已经创建的实例
var typeInstanceCache = make(map[int]*Type)

// 创建枚举
// 根据value获取枚举
func TypeByValue(value int) *Type {
	if instance, exists := typeInstanceCache[value]; exists {
		return instance
	}
	e := &Type{}
	enum.SetEnumInstance(&e.Enum, e, value)
	typeInstanceCache[value] = e
	return e
}

var TypeEnum *Type = func() *Type {
	e := &Type{}
	enum.SetEnumInstance(&e.Enum, e)
	return e
}()
